package com.zhongxia.controller;

import com.zhongxia.entity.Menu;
import com.zhongxia.entity.MenuVO;
import com.zhongxia.feign.MenuFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/3/30 19:24
 */
@Controller
@RequestMapping("clientmenu")
public class ClientMenu {
    @Autowired
    private MenuFeign menuFeign;
    @GetMapping("findAll")
    @ResponseBody
    public MenuVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit)
    {
        int index=(page-1)*limit;
        return menuFeign.findAll(index, limit);
    }
    @GetMapping("index")
    public String index()
    {
        return "index";
    }
    @GetMapping("manage")
    public String manage()
    {
        return "menu_manage";
    }
    @GetMapping("deleteById/{id}")
    public String deleteById(@PathVariable("id") int id)
    {
        menuFeign.deleteById(id);
        return "menu_manage";
    }
    @GetMapping("findType")
    public ModelAndView findType()
    {
        ModelAndView mv=new ModelAndView();
        mv.setViewName("menu_add");
        mv.addObject("list",menuFeign.findType());
        return mv;
    }
    @GetMapping("/findById/{id}")
    public String findById(@PathVariable("id") int id, Model model){
        model.addAttribute("list",menuFeign.findType());
        model.addAttribute("menu",menuFeign.findById(id));
        return "menu_update";
    }
    @PostMapping("save")
    public String save(Menu menu)
    {
        menuFeign.save(menu);
        return "menu_manage";
    }
    @PostMapping("update")
    public String update(Menu menu)
    {
        menuFeign.update(menu);
        return "menu_manage";
    }
}
